require File.dirname(__FILE__)+"/../../../test_helper"
require "starframe/sprite"
require "starframe/sprite/collision"
require "starframe/sprite/collision/dot"
require "starframe/sprite/collision/circle"

class TestStarFrameSpriteCollisionCircle < Test::Unit::TestCase
  class TestSprite < StarFrame::Sprite
    @texture = StarRuby::Texture.load "test"
  end
  def setup
    @sprite1 = TestSprite.new(0, 0)
    @sprite2 = TestSprite.new(0, 0)
  end
  
  def test_collides_circle_circle
    circle1 = StarFrame::Sprite::Collision::Circle.new(@sprite1, nil, 0, 0, 1)
    circle2 = StarFrame::Sprite::Collision::Circle.new(@sprite2, nil, 0, 0, 1)
    
    (-3..3).each do |@sprite2.x|
      (-3..3).each do |@sprite2.y|
        result = ((@sprite2.x**2 + @sprite2.y**2) <= 2**2)
        assert_equal result, circle1.collide?(circle2), "#{@sprite2.x},#{@sprite2.y}"
        assert_equal result, circle2.collide?(circle1), "#{@sprite2.x},#{@sprite2.y}"
      end
    end
  end
  
  def test_collides_circle_dot
    circle1 = StarFrame::Sprite::Collision::Circle.new(@sprite1, nil, 0, 0, 1)
    dot2    = StarFrame::Sprite::Collision::Dot.new(@sprite2, nil, 0, 0)
    (-3..3).each do |@sprite2.x|
      (-3..3).each do |@sprite2.y|
        result = (((-1..1) === @sprite2.x && @sprite2.y == 0) || (@sprite2.x == 0 && (-1..1) === @sprite2.y))
        assert_equal result, circle1.collide?(dot2), "#{@sprite2.x},#{@sprite2.y}"
        assert_equal result, dot2.collide?(circle1), "#{@sprite2.x},#{@sprite2.y}"
      end
    end
  end
end
